package com.skyolder.milkbee.web.rest.my;

import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.codahale.metrics.annotation.Timed;
import com.skyolder.milkbee.domain.Ware;
import com.skyolder.milkbee.service.WareService;
import com.skyolder.milkbee.web.rest.util.PaginationUtil;

import io.swagger.annotations.ApiParam;

/**
 * REST controller for managing Ware.
 */
@RestController("myWareResource")
@RequestMapping("/api/my")
public class WareResource {

    private final Logger log = LoggerFactory.getLogger(WareResource.class);
        
    @Inject
    private WareService wareService;



    /**
     * GET  /wares : get all the wares.
     *
     * @param pageable the pagination information
     * @return the ResponseEntity with status 200 (OK) and the list of wares in body
     * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
     */
    @GetMapping("/wares")
    @Timed
    public ResponseEntity<List<Ware>> getAllWares(@ApiParam Pageable pageable)
        throws URISyntaxException {
        log.debug("REST request to get a page of Wares");
        Page<Ware> page = wareService.findAll(pageable);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/wares");
        return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
    }

    /**
     * GET  /wares/:id : get the "id" ware.
     *
     * @param id the id of the ware to retrieve
     * @return the ResponseEntity with status 200 (OK) and with body the ware, or with status 404 (Not Found)
     */
    @GetMapping("/wares/{id}")
    @Timed
    public ResponseEntity<Ware> getWare(@PathVariable Long id) {
        log.debug("REST request to get Ware : {}", id);
        Ware ware = wareService.findOne(id);
        return Optional.ofNullable(ware)
            .map(result -> new ResponseEntity<>(
                result,
                HttpStatus.OK))
            .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }
}
